//获取应用实例
var app = getApp();
Page({
    data: {
		isShowFootNav: false,
		isShowAddMore: true,
		platform: "iPhone", 
		
		name: '',
		cellNum: '',
		fullAddr: '',	
		canUseList: [], //3条数据
		canUseListAdd: [], //3条后的数据	
	},
	// 切换更多或收起
	addMore() {
		if (!this.data.addMore) {
			this.setData({
				canUseList: [...this.data.canUseList, ...this.data.canUseListAdd]
			})
		} else {
			this.setData({
				canUseList: this.data.canUseList.slice(0,3)
			})
		}
		this.setData({
			addMore: !this.data.addMore
		})
	},
	
    onLoad: function () {
    	app.setStorageSync(app.globalData.callVisaSign,1)  //用于首页是否调用签注类别标记
	    if (app.isAndroid()) {
		    this.setData({platform: "android"});
	    }

		let cachePayMnet = app.getStorageSync(app.globalData.cacheConfirem),
			canUseList = JSON.parse(cachePayMnet.info),
			money = JSON.parse(cachePayMnet.money);

		this.setData({
			licensingWay: cachePayMnet.licensingWay, //1 上门 2 邮寄
			directType: cachePayMnet.directType, //1 专业 2非专业
			name: cachePayMnet['address.contactName'],
			cellNum: cachePayMnet['address.cellNum'],
			fullAddr: cachePayMnet['address.fullAddr'],
			//非专业
			inlandCarNbr: cachePayMnet.inlandCarNbr, //车牌
			carArchivesNbr: cachePayMnet.carArchivesNbr, //档案号
			inlandTelNbr: cachePayMnet.inlandTelNbr, //内地手机号码
			//专业
			witnessName: cachePayMnet.witnessName, //办理人姓名
			fileNbr: cachePayMnet.fileNbr, //卷宗号
			
			payType: money.payType, //支付类型
			workBookFee: money.workBookFee/100, 
			serviceFee: money.serviceFee/100,
			workBookFeeAll: (money.workBookFee/100)*money.handleCount, //工本总费用费
			serviceFeeAll: (money.serviceFee/100)*money.handleCount, //服务总费用费
			totalFee: money.totalFee/100, //总费用
			handleCount: money.handleCount //订单数
		})
		if (canUseList.length > 3) { //可预期
			this.setData({
				addMore: false, //显示 更多文案
				isShowAddMore: true, //隐藏按钮
				canUseList: canUseList.slice(0,3),  //如果列表长度大于3，先显示3个
				canUseListAdd: canUseList.slice(3)
			})
		} else {
			this.setData({
				canUseList: canUseList,
				isShowAddMore: false //隐藏按钮
			})
		}
    },

    toUrl: function (e) {
		app.setStorageSync(app.globalData.passCache,e.currentTarget.dataset.pass)
		app.navigateTo({url:'../passInformation/passInformation'})
    },

    formSubmit:function (e) {
	    let that = this,
			formResult = app.getStorageSync(app.globalData.cacheConfirem);
			delete formResult['money']
			
			formResult['platform'] = this.data.platform,
			formResult['payType'] = formResult.payType
			formResult['formId'] = e.detail.formId;

        var opt = {
         url: app.globalData.host+"/wx/hkmdc/pay.ajax",
         data: formResult,
         sucFn:function (result) {			
			if (formResult.licensingWay == 1) {
				app.setStorageSync(app.globalData.paySuccess, result.body.orderIds);
				app.redirectTo({url:'../paysuccess/paysuccess'})
				return;
			}
			var resObject = result.body.wxPayInfo;
			var res = {
				timeStamp: resObject.timeStamp,
				nonceStr: resObject.nonceStr,
				package: resObject.packageName,
				signType:resObject.signType,
				paySign: resObject.paySign,
				sucFn: function (e) {
					var opt1 = {
						url: app.globalData.host+"/wx/hkmdc/payCallback.ajax",
						data: {
							orderId: result.body.payOrderId,
							prepayId: resObject.prepayId,
							moduleOrderId: result.body.payOrderId,
							platform: that.data.platform
						},
						sucFn: function (res) {
							app.setStorageSync(app.globalData.paySuccess, result.body.orderIds);
							app.redirectTo({url:'../paysuccess/paysuccess'})
						}
					}
					app.ajax(opt1);
				},
				failFn: function (e) {
					console.error('支付失败',e)
				}
			}
			app.requestPayment(res)
         }
        };
        app.ajax(opt);
    }
});
